package org.tastefuljava.minica;

import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;

public class PrivateKeyEntry extends KeyStoreEntry {
    private PrivateKey key;
    private X509Certificate chain[];

    public PrivateKeyEntry(String alias, PrivateKey key,
            X509Certificate chain[]) {
        super(alias, true);
        this.key = key;
        this.chain = chain;
    }

    public PrivateKey getKey() {
        return key;
    }

    public X509Certificate[] getChain() {
        return chain;
    }

    @Override
    public KeyStoreEntry copy(String newName) {
        return new PrivateKeyEntry(newName, key, chain);
    }

    @Override
    public void addTo(KeyStore ks, char[] password) throws KeyStoreException {
        ks.setKeyEntry(getAlias(), key,
                        password, chain);
    }
}
